package aygx.spring.boot.principle;

import aygx.spring.boot.principle.entity.Dog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

/**
 * @author 暗影孤星
 * @date 2022/7/21 23:08
 * @description Spring Boot 原理
 * classpath:引入的是resources下面的文件，直接引入的是java下面的文件
 */
@Slf4j
@ComponentScan("aygx")
@ImportResource("classpath:spring.xml")
@Import(Dog.class)
public class Content1 {
    public static void main(String[] args) {
        // ApplicationContext content = new ClassPathXmlApplicationContext("spring.xml");
        ApplicationContext content = new AnnotationConfigApplicationContext(Content1.class);
        // Object is aygx.spring.boot.principle.service.impl.ScheduleServiceImpl@6f152006
//        for (String beanDefinitionName : content.getBeanDefinitionNames()) {
//            // bean name is principleApplication
//            // bean name is baseController
//            // bean name is scheduleServiceImpl
//            // bean name is people1
//            // bean name is people2
//            // bean name is scheduleService
//            log.info("bean name is {}", beanDefinitionName);
//        }
//        // proxyBeanMethods = true
//        ComponentConfig componentConfig1 = content.getBean("componentConfig", ComponentConfig.class);
//        ComponentConfig componentConfig2 = content.getBean("componentConfig", ComponentConfig.class);
//        // componentConfig1, aygx.spring.boot.principle.config.ComponentConfig$$EnhancerBySpringCGLIB$$c7615dc@9597028
//        // componentConfig2, aygx.spring.boot.principle.config.ComponentConfig$$EnhancerBySpringCGLIB$$c7615dc@9597028
//        // people1, aygx.spring.boot.principle.entity.People@1b7cc17c
//        // people1, aygx.spring.boot.principle.entity.People@1b7cc17c
//        log.info("componentConfig1, {}",componentConfig1);
//        log.info("componentConfig2, {}",componentConfig2);
//        log.info("people1, {}",componentConfig1.people1());
//        log.info("people1, {}",componentConfig1.people1());
//
//
//        // proxyBeanMethods = false
//        ComponentConfig componentConfig3 = content.getBean("componentConfig", ComponentConfig.class);
//        ComponentConfig componentConfig4 = content.getBean("componentConfig", ComponentConfig.class);
//        // componentConfig3, aygx.spring.boot.principle.config.ComponentConfig@1ffe63b9
//        // componentConfig4, aygx.spring.boot.principle.config.ComponentConfig@1ffe63b9
//        // people1, aygx.spring.boot.principle.entity.People@1677d1
//        // people1, aygx.spring.boot.principle.entity.People@48fa0f47
//        log.info("componentConfig3, {}",componentConfig3);
//        log.info("componentConfig4, {}",componentConfig4);
//        log.info("people1, {}",componentConfig3.people1());
//        log.info("people1, {}",componentConfig3.people1());


        // @Import() 导入时被导入的bean无需任何声明，且bean名称为全限定类名
        for (String beanDefinitionName : content.getBeanDefinitionNames()) {
            // bean name is aygx.spring.boot.principle.entity.Dog
            log.info("bean name is {}", beanDefinitionName);
        }
    }
}
